package org.erp.common.context;

import java.util.List;

public class StockLockContext {
    private static final ThreadLocal<String> batchKeyHolder = new ThreadLocal<>();

    private static final ThreadLocal<List<String>> internalIdsTL = new ThreadLocal<>();

    private static final ThreadLocal<Boolean> hasExternalTL = new ThreadLocal<>();

    public static void setBatchKey(String batchKey) {
        batchKeyHolder.set(batchKey);
    }

    public static String getBatchKey() {
        return batchKeyHolder.get();
    }

    public static void setInternalIds(List<String> ids) {
        internalIdsTL.set(ids);
    }

    public static List<String> getInternalIds() {
        return internalIdsTL.get();
    }

    public static void setHasExternal(boolean flag) {
        hasExternalTL.set(flag);
    }

    public static boolean hasExternal() {
        return Boolean.TRUE.equals(hasExternalTL.get());
    }

    public static void clear() {
        batchKeyHolder.remove();
        internalIdsTL.remove();
        hasExternalTL.remove();
    }
}
